package gui;

import protocol.generic.AbstractProtocolManager;
import protocol.generic.Group;

import com.trolltech.qt.gui.QDialog;

public class Rename extends QDialog{
	MainWindow mw;
	String old;
	Ui_Rename ui=new Ui_Rename();
	
	public Rename(MainWindow mw,String old){
		super(mw);
		this.mw=mw;
		this.old=old;
		ui.setupUi(this);
		this.show();
		
	}
	
	public void accept(){
		String olds[]=old.split("#");
		if(olds.length==1){
			for(AbstractProtocolManager manager : this.mw.protocolManagers){
				try{
					manager.renameGroup(old, ui.nameEdit.text());
				}
				catch(Exception e){
					//ignore it
				}
			}
			for(Group group : this.mw.buddyList.groupList){
				if(group.getName().equalsIgnoreCase(old))
					group.setName(ui.nameEdit.text());
			}
		}
		else{
			//rename entry
		}
		
		this.mw.buddyList.layoutChanged.emit();
	}
}
